package juhe_api

import (
	"base-web/global"
	"fmt"
)

var (
	jokeUrl    = "http://v.juhe.cn/joke/content/list.php"
	toutiaoUrl = "http://v.juhe.cn/toutiao/index"
	weatherUrl = "http://apis.juhe.cn/simpleWeather/query"
	japiUrl    = "http://api.juheapi.com/japi/toh"
	mobileUrl  = "http://apis.juhe.cn/mobile/get"
)

//笑话大全
//@page 页数
//@pagesize 每页数量
func JuHeJokeList(page, pagesize string) (juhe JuHeReponse, err error) {
	key := global.BASE_CONFIG.JuHeApi.JokeKey
	url := fmt.Sprintf(jokeUrl+"?key=%s&page=%s&pagesize=%s&sort=asc&time=%s", key, page, pagesize, "1418816972")
	err = getApi(url, &juhe)
	if err != nil {
		return
	}
	return
}

//新闻头条
func JuHeToutiaoList() (juhe JuHeReponse, err error) {
	key := global.BASE_CONFIG.JuHeApi.ToutiaoKey
	url := fmt.Sprintf(toutiaoUrl+"?type=top&key=%s", key)
	err = getApi(url, &juhe)
	if err != nil {
		return
	}
	return
}

//天气预报
//@city 城市
func JuHeWeatherList(city string) (juhe JuHeReponse, err error) {
	key := global.BASE_CONFIG.JuHeApi.WeatherKey
	url := fmt.Sprintf(weatherUrl+"?key=%s&city=%s", key, city)
	err = getApi(url, &juhe)
	if err != nil {
		return
	}
	return
}

//历史上的今天
//@month 月份
//@day 日
func JuHeJapiList(month, day string) (juhe JuHeReponse, err error) {
	key := global.BASE_CONFIG.JuHeApi.JapiKey
	url := fmt.Sprintf(japiUrl+"?key=%s&v=1.0&month=%s&day=%s", key, month, day)
	err = getApi(url, &juhe)
	if err != nil {
		return
	}
	return
}

//手机号归属地查询
//@mobile 手机号
func JuHeMobile(mobile string) (juhe JuHeReponse, err error) {
	key := global.BASE_CONFIG.JuHeApi.MobileKey
	url := fmt.Sprintf(mobileUrl+"?phone=%s&key=%s", mobile, key)
	err = getApi(url, &juhe)
	if err != nil {
		return
	}
	return
}
